<template>
  <div class="home" style="padding:10px;">
    <h3>Form (校验表单)</h3>
    <lbr-form ref="form" :model="formData" :rules="rules">
      <lbr-form-item label="名称：" prop="name">
        <lbr-input v-model="formData.name"></lbr-input>
      </lbr-form-item>
      <lbr-form-item label="邮箱：" prop="mail">
        <lbr-input v-model="formData.mail"></lbr-input>
      </lbr-form-item>
      <div style="height:20px;"></div>
      <lbr-button type="primary" @click="handleSubmit">提交</lbr-button>
      <div style="height:20px;"></div>
      <lbr-button @click="handleReset">重置</lbr-button>
    </lbr-form>
  </div>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      formData: { name: "", mail: "" },
      rules: {
        name: [{ required: true, message: "不能为空", trigger: "blur" }],
        mail: [
          { required: true, message: "不能为空", trigger: "blur" },
          { type: "email", message: "邮箱格式不正确", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) console.log("提交成功");
        else console.log("校验失败");
      });
    },
    handleReset() {
      this.$refs.form.resetFields();
    }
  }
};
</script>